import { _decorator, CCBoolean, CCString, Component, Label, Node } from 'cc';
import { EDITOR } from 'cc/env';
const { ccclass, property } = _decorator;

@ccclass('ULabel')
export class ULabel extends Label {
    @property
    private _defaultStr: string = ""
    @property({ type: CCString, displayName: "String", override: true})
    public set string(v: string) {
        if (EDITOR && this._isTemp) {
            this._defaultStr = v
        }

        if (!EDITOR) {
            this._defaultStr = ""
        }

        super.string = v
    }

    public get string(): string {
        if(this._string){
            return this._string
        }
        
        return this._defaultStr
    }

    @property
    private _isTemp: boolean = false
    @property({ type: CCBoolean, displayName: "是否占位符"})
    public set isTemp(b: boolean) {
        this._isTemp = b
        this._defaultStr = b ? this._string : ""
    }

    public get isTemp(): boolean {
        return this._isTemp
    }

    onLoad(): void {
        if (!EDITOR && this._isTemp) {
            this._defaultStr = this._string
            this._string = ""
            // this.markForUpdateRenderData()
        }
    }

}


